from rest_framework import serializers
from apps.cart.models import Cart, CartItem
from apps.goods.models import Goods
from apps.goods.serializers import GoodsSerializer


class CartSerializer(serializers.ModelSerializer):
    class Meta:
        model = Cart
        fields = '__all__'

class CartItemSerializer(serializers.ModelSerializer):
    class Meta:
        model = CartItem
        fields = '__all__'

class CartDetailSerializer(serializers.ModelSerializer):
    good = serializers.SerializerMethodField()

    def get_good(self, obj):
        # print(obj.good.good_id)
        good = Goods.objects.filter(good_id=obj.good.good_id).first()
        good_ser = GoodsSerializer(instance=good).data
        return good_ser
    class Meta:
        model = CartItem
        fields = '__all__'